home *** CD-ROM | disk | FTP | other *** search
- Path: wkaufman.us.oracle.com!wkaufman
- From: wkaufman@wkaufman.us.oracle.com (William Kaufman)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: 10 Mar 1996 17:39:58 GMT
- Organization: Oracle Corporation, Redwood Shores CA
- Message-ID: <4hv45e$svm@inet-nntp-gw-1.us.oracle.com>
- References: <4htonk$350@news.hklink.net>
- NNTP-Posting-Host: wkaufman.us.oracle.com
-
- In article <4htonk$350@news.hklink.net> alex@station.net (Alex Chu) writes:
- ]
- ] main()
- ] {
- ] PITEM head, current;
- ] head=(PITEM) malloc(sizeof(ITEM));
- ] ^^^^^^^
- ] head->val=1;
- ] }
- ]
- ] I want to know why need to use the type casting PITEM in front of the
- ] malloc ? Please help!
-
- Either:
-
- a) you're using a pre-ANSI compiler which complains that you can't
- portably cast from (char *) to (PITEM) (in which case, you could go and
- get an ANSI compiler); or,
-
- b) you aren't including <stdlib.h>, where malloc() is defined as
- returning (void *), and the compiler thinks it returns (int).
-
- -- Bill K.
-
- Bill Kaufman | "I mean ... it's not even been a two-and-two-make-
- wkaufman@us.oracle.com | five sort of day, it's more like a two-and-two-
- | make ... *fish* ..." -- "Cages", Dave McKean
-